﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;

namespace PMS
{
    /// <summary>
    /// 数据层 仓储
    /// </summary>
    public partial class DALSession
    {
    
        #region 0.4 获取当前 操作上下文 + OperateContext Current
        /// <summary>
        /// 获取当前 操作上下文 (为每个处理浏览器请求的服务器线程 单独创建 操作上下文)
        /// </summary>
        public static DALSession Current
        {
            get
            {
                DALSession dalSession = CallContext.GetData(typeof(DALSession).Name) as DALSession;
                if (dalSession == null)
                {
                    dalSession = new DALSession();
                    CallContext.SetData(typeof(DALSession).Name, dalSession);
                }
                return dalSession;
            }
        }
        #endregion

        public DbContext Db {
            get {
                return DBContextFactory.GetDbContext();// = new MODEL.OuOAEntities();
            }
        }

        public  bool Savechanges() {

            return Db.SaveChanges() > 0;
        }

    }
}
